package cn.changeforyou.web.cloud.auth.controller;

import cn.changeforyou.web.cloud.auth.dapator.ReactAdminPage;
import cn.changeforyou.web.cloud.auth.entity.RoleInfo;
import cn.changeforyou.web.cloud.auth.service.RoleInfoService;
import cn.changeforyou.web.cloud.webBase.common.model.Result;
import cn.changeforyou.web.cloud.webBase.controller.AbstractController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController extends AbstractController {

    @Resource
    private RoleInfoService roleInfoService;

    @GetMapping("queryRoleByPage")
    public Result<ReactAdminPage<RoleInfo>> queryRoleByPage(){
        return Result.success(new ReactAdminPage<>(roleInfoService.queryRoleByPage()));
    }

    @GetMapping("getRoleById")
    public Result<RoleInfo> getRoleById(Integer id) {
        validIsNull(id);
        return Result.success(roleInfoService.getById(id));
    }

    @GetMapping("queryEnabledRoles")
    public Result<List<RoleInfo>> queryEnabledRoles() {
        return Result.success(roleInfoService.queryEnabledRoles());
    }
}
